package com.samoiloff.ui.list.smart.controller {
	import flash.events.MouseEvent;
	import flash.events.Event;
	import com.samoiloff.framework.controller.AbstractController;
	import com.samoiloff.ui.list.smart.model.SmartListModel;
	import com.samoiloff.ui.scroll.resize.ResizeScroll;

	/**
	 * @author Samoiloff
	 */
	public class SmartListScrollController extends AbstractController {
		
		private var _listModel: SmartListModel;

		private var _scroll: ResizeScroll;
		
		public function SmartListScrollController(model: SmartListModel) {
			super(model);
			
			_listModel = model;
			
			_scroll = _listModel.view.scroll;
			
			_listModel.mainMc.addChild(_scroll);
			
			_listModel.addEventListener(Event.RESIZE, onResize);
			_listModel.mainMc.addEventListener(MouseEvent.MOUSE_WHEEL, onWheel);
			
			onResize();
		}

		private function onWheel(e:MouseEvent): void {
			_scroll.scrollPosition -= e.delta*5;
		}

		private function onResize(event: Event = null): void {
			_scroll.x = _listModel.width - _scroll.width;
			_scroll.height = _listModel.height;
		}
	}
}
